package src.leetcode.everyday.hard_0887;

public class superEggDrop {
    public static void main(String[] args)
    {
        Solution solution = new Solution();
        System.out.println(solution.superEggDrop(10, 10));
    }
}

class Solution {
    public int superEggDrop(int k, int n) {
        int dp[][] = new int [k + 1][n + 1];
        for(int i = 0; i <= k; i++) {
            for(int j = 0; j <= n; j++){
                System.out.print(dp[i][j] + " ");
            }
            System.out.println();
        }
        for(int i = 1; i <= n; i++) {
            dp[1][i] = i;
        }
        for(int i = 1; i <= k; i++) {
            dp[i][1] = 1;
        }


        for(int i = 2; i <= k; i++) {
            for(int j = 2; j <= n; j++) {
                int min = Math.max(dp[i - 1][0], dp[i][j - 1]) + 1;
                for(int l = 2; l <= j; l++) {
                    int a = Math.max(dp[i - 1][l - 1], dp[i][j - l]) + 1;
                    if(min > a) min = a;
                    else break;
                }
                dp[i][j] = min;
            }
        }

        return dp[k][n];
    }
}
